package myServlet;

import Smt.ServerImp.SupplierServerImp;
import Smt.Util.Supplier;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@SuppressWarnings("serial")
public class SupplierAdd extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		String ids = request.getParameter("iid");
		int id = 0;
		if (ids != null) {
			id = Integer.parseInt(ids);
		}
		String name = request.getParameter("iname");
		String description = request.getParameter("idescription");
		String atten = request.getParameter("iatten");
		String tel = request.getParameter("itel");
		String add = request.getParameter("iadd");
		Supplier s = new Supplier(id, name, description, atten, tel, add);
		SupplierServerImp ssi = new SupplierServerImp();
		if (ssi.add(s)) {
			response.sendRedirect("SupplierRead");
		} else {
			request.setAttribute("error", "编号已存在，添加失败！");
			request.getRequestDispatcher("SupplierRead").forward(request, response);
		}

	}

}
